export default class Matrix {

  static createArray(rowNum, colNum) {
    let newArr = [];
    for (let k = 0; k < rowNum; k++) {
      newArr[k] = [];
      for (let j = 0; j < colNum; j++) {
        newArr[k][j] = {};
      }
    }
    return newArr;
  }


  /**
   * 二维数组去重 todo
   * @param arr
   * @returns {Array}
   */
  static uniqueRemove(arr) {
    let arrnew = [];
    let set = new Set();
    for (let i = 0; i < arr.length; i++) {
      set.add(arr[i].join(''));
    }
    arrnew = [...set];

    let newarr = [];
    for (let i = 0; i < arrnew.length; i++) {
      newarr.push(arrnew[i].split(''));
    }
    return newarr;
  }

  /**
   * 数组交换指定元素
   * @param arr
   * @param x1
   * @param y1
   * @param x2
   * @param y2
   * @returns {*}
   */
  static exchange(arr, x1, y1, x2, y2) {
    let tmp = arr[y1][x1];
    arr[y1][x1] = arr[y2][x2];
    arr[y2][x2] = tmp;
    return arr;
  }
}